home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / game / shoot / ADoom_src_1_2.lha / ADoom_src / ADoom_SndSrvr.s next >
Text File  |  1998-03-05  |  50KB  |  2,331 lines

  1.         mc68020
  2.  
  3. ;------------------------------------------------------------------------
  4. ; Sound Server for ADoom/ADoomPPC - by Joseph Fenton
  5. ;
  6. ; Server is LoadSeg'd by ADoom/ADoomPPC and called
  7. ; via entry points in the start of the segment.
  8. ;
  9. ; Entry Points:
  10. ;    InitServer - open audio.device, allocate and lock channels,
  11. ;        setup sound interrupt handler, and setup locals.
  12. ;        Note: future Sound Servers may do other setups
  13. ;        in order to do MIDI or use 16bit sound cards.
  14. ;               returns 0 if okay, -1 otherwise.
  15. ;    ExitServer - restores audio interrupt, cleanup audio,
  16. ;        and frees any local memory.
  17. ;    Sfx_SetVol - pass in the new sound effects volume in d0.
  18. ;    Sfx_Start - pass in new sound effect to play. a0 = wave,
  19. ;        d0 = cnum, d1 = pitch, d2 = vol, d3 = sep, d4 =
  20. ;        length.
  21. ;    Sfx_Update - pass in new settings for a sfx. a0 = data,
  22. ;        d0 = cnum, d1 = pitch, d2 = vol, d3 = sep.
  23. ;    Sfx_Stop - stop a playing sound effect. d0 = cnum.
  24. ;    Sfx_Done - check if sound effect playing. d0 = cnum; returns
  25. ;        d0 = 0 if not playing/current index if playing.
  26. ;    Mus_SetVol - pass in the new music volume in d0.
  27. ;    Mus_Register - pass in pointer to MUS data to register in
  28. ;        a0. Returns handle in d0.
  29. ;    Mus_Unregister - pass in handle to music to unregister in d0.
  30. ;    Mus_Play - pass in handle to music to start playing in d0,
  31. ;        pass the looping flag in d1.
  32. ;    Mus_Stop - pass in handle to music to stop playing in d0.
  33. ;    Mus_Pause - pass in handle to music to pause in d0.
  34. ;    Mus_Resume - pass in handle to music to resume in d0.
  35. ;    Mus_Done - return d0 = 0 if music not playing
  36. ;
  37. ;------------------------------------------------------------------------
  38.  
  39.  
  40. _custom        equ    $DFF000
  41.  
  42. ;DEBUGGING    equ    1
  43.  
  44. ;------------------------------------------------------------------------
  45.  
  46. ;        include    devpac:system.gs    ; all includes/LVOs
  47.  
  48.         include    "exec/exec.i"
  49.         include    "exec/funcdef.i"
  50.         include    "exec/exec_lib.i"
  51.         include    "dos/dos.i"
  52.         include    "dos/dos_lib.i"
  53.         include    "graphics/gfxbase.i"
  54.         include    "devices/audio.i"
  55.         include    "hardware/custom.i"
  56.         include    "hardware/intbits.i"
  57.         include    "hardware/dmabits.i"
  58.  
  59. CALLSYS        macro
  60.         jsr    (_LVO\1,a6)
  61.         endm
  62.  
  63. CALLDOS        macro
  64.         movea.l    (_DOSBase,pc),a6
  65.         jsr    (_LVO\1,a6)
  66.         endm
  67.  
  68.         output    ADoom_SndSrvr
  69.  
  70.         IFD    DEBUGGING
  71. start        jsr    InitServer
  72.  
  73. ; test music
  74.         lea    MUSData,a0
  75.         jsr    Mus_Register
  76.         moveq    #0,d1            ; no looping
  77.         jsr    Mus_Play
  78. .l1        jsr    Mus_Done
  79.         tst.l    d0
  80.         bne.b    .l1
  81.  
  82.         moveq    #1,d1            ; looping
  83.         jsr    Mus_Play
  84.         move.l    #500,d1
  85.         CALLDOS    Delay
  86.         jsr    Mus_Pause
  87.         move.l    #500,d1
  88.         CALLDOS    Delay
  89.         jsr    Mus_Resume
  90.         move.l    #500,d1
  91.         CALLDOS    Delay
  92.         jsr    Mus_Stop
  93.         jsr    Mus_Unregister
  94.  
  95. ; test sfx
  96.         IFD    DEBUGGINGSFX
  97.  
  98.         lea    MI_127,a0
  99.         moveq    #0,d0
  100.         move.l    #11025,d1
  101.         moveq    #127,d2
  102.         move.l    #128,d3
  103.         move.l    #4220,d4
  104.         jsr    Sfx_Start
  105. .l2        moveq    #0,d0
  106.         jsr    Sfx_Done
  107.         tst.l    d0
  108.         bne.b    .l2
  109.  
  110.         lea    MI_127,a0
  111.         moveq    #1,d0
  112.         move.l    #11025,d1
  113.         moveq    #127,d2
  114.         move.l    #0,d3
  115.         move.l    #4220,d4
  116.         jsr    Sfx_Start
  117. .l3        moveq    #1,d0
  118.         jsr    Sfx_Done
  119.         tst.l    d0
  120.         bne.b    .l3
  121.  
  122.         moveq    #50,d1
  123.         CALLDOS    Delay
  124.  
  125.         lea    MI_127,a0
  126.         moveq    #0,d0
  127.         move.l    #11025,d1
  128.         moveq    #127,d2
  129.         move.l    #255,d3
  130.         move.l    #4220,d4
  131.         jsr    Sfx_Start
  132. .l4        moveq    #0,d0
  133.         jsr    Sfx_Done
  134.         tst.l    d0
  135.         bne.b    .l4
  136.  
  137.         ENDC
  138.  
  139.         jsr    ExitServer
  140.         moveq    #0,d0
  141.         rts
  142.  
  143.         CNOP    0,16
  144.  
  145. MUSData        ;incbin    D_INTRO.MUS
  146.         incbin    MUS/D_E1M2.MUS
  147.  
  148.         IFD    DEBUGGINGSFX
  149. MI_127        incbin    mi_127
  150.         ;incbin    mp_1
  151.         ENDC
  152.  
  153.         ENDC
  154.  
  155. ;------------------------------------------------------------------------
  156.  
  157. Header        moveq    #0,d0
  158.         rts
  159.         dc.l    'SSRV'            ; 4  signature
  160.         bra.w    InitServer        ; 8
  161.         bra.w    ExitServer        ;12
  162.         bra.w    Sfx_SetVol        ;16
  163.         bra.w    Sfx_Start        ;20
  164.         bra.w    Sfx_Update        ;24
  165.         bra.w    Sfx_Stop        ;28
  166.         bra.w    Sfx_Done        ;32
  167.         bra.w    Mus_SetVol        ;36
  168.         bra.w    Mus_Register        ;40
  169.         bra.w    Mus_Unregister        ;44
  170.         bra.w    Mus_Play        ;48
  171.         bra.w    Mus_Stop        ;52
  172.         bra.w    Mus_Pause        ;56
  173.         bra.w    Mus_Resume        ;60
  174.         bra.w    Mus_Done        ;64
  175.  
  176.         dc.b    '$VER: ADoom/ADoomPPC Sound Server 1.0 (19.02.98)',0
  177.         dc.b    'This sound server uses the Amiga audio.device and',0
  178.         dc.b    '11KHz samples; it supports full stereo panning on',0
  179.         dc.b    'sound effects and music.  Up to 16 sound effects and',0
  180.         dc.b    '16 channels of music can be palying at any time.',0
  181.  
  182. ;------------------------------------------------------------------------
  183.  
  184.         CNOP    0,16
  185.  
  186. InitServer    movem.l    d1-d7/a0-a6,-(a7)
  187.         movea.l    4.w,a6
  188.         move.l    a6,_ExecBase
  189.  
  190.         moveq    #0,d0
  191.         lea    DOSName,a1
  192.         CALLSYS    OpenLibrary
  193.         move.l    d0,_DOSBase
  194.         beq    .err            ; couldn't open dos.library
  195.  
  196.         moveq    #39,d0
  197.         lea    GfxName,a1
  198.         CALLSYS    OpenLibrary
  199.         tst.l    d0
  200.         beq.b    .2            ; leave at default (NTSC)
  201.         move.l    d0,a1
  202.         btst    #REALLY_PALn,gb_DisplayFlags(a1)
  203.         beq.b    .1            ; crystal is NTSC
  204.         move.w    #322,period        ; PAL sample rate
  205. .1        CALLSYS    CloseLibrary
  206.  
  207. .2        move.l    #128*256,d0
  208.         move.l    #MEMF_CLEAR+MEMF_FAST+MEMF_PUBLIC,d1
  209.         CALLSYS    AllocVec
  210.         move.l    d0,LookupMem
  211.         beq    .err0            ; no memory for vol_lookup
  212.         move.l    d0,vol_lookup
  213.         movea.l    d0,a0
  214.  
  215.         moveq    #0,d2
  216.         moveq    #0,d1
  217. .3        move.b    d1,d3
  218.         ext.w    d3
  219.         muls.w    d2,d3
  220.         divs.w    #127,d3            ; i*j/127
  221.         move.b    d3,(a0)+
  222.         addq.b    #1,d1
  223.         bne.b    .3
  224.         addq.b    #1,d2
  225.         cmpi.b    #128,d2
  226.         bne.b    .3
  227.  
  228.         CALLSYS    CreateMsgPort
  229.         move.l    d0,AudioPort
  230.         beq    .err1            ; couldn't create port
  231.         movea.l    d0,a0
  232.         move.l    #ioa_SIZEOF,d0
  233.         CALLSYS    CreateIORequest
  234.         move.l    d0,AudioIO
  235.         beq    .err2            ; couldn't create io
  236.  
  237.         movea.l    d0,a1
  238.         moveq    #0,d0
  239.         moveq    #0,d1
  240.         lea    AudioName,a0
  241.         CALLSYS    OpenDevice
  242.         tst.l    d0
  243.         bne    .err3            ; couldn't open audio.device
  244.  
  245.         movea.l    AudioIO,a1
  246.         move.w    #ADCMD_ALLOCATE,IO_COMMAND(a1)
  247.         move.b    #ADIOF_NOWAIT+IOF_QUICK,IO_FLAGS(a1)
  248.         move.l    #AudioAlloc,ioa_Data(a1)
  249.         move.l    #1,ioa_Length(a1)
  250.         movea.l    IO_DEVICE(a1),a6
  251.         jsr    DEV_BEGINIO(a6)
  252.         movea.l    _ExecBase,a6
  253.         tst.l    d0
  254.         bne    .err4            ; couldn't allocate channels
  255.  
  256.         movea.l    AudioIO,a1
  257.         move.w    #ADCMD_LOCK,IO_COMMAND(a1)
  258.         CALLSYS    SendIO
  259.  
  260.         lea    _custom,a0
  261.         move.w    #$0780,intena(a0)    ; kill int enable
  262.         move.w    #$0780,intreq(a0)    ; kill request
  263.         move.w    #$00FF,adkcon(a0)    ; kill modulation
  264.         move.w    #$000F,dmacon(a0)    ; disable dma
  265.  
  266.         move.l    #ClearBuf,aud0(a0)
  267.         move.w    #40,aud0+ac_len(a0)
  268.         move.w    period,aud0+ac_per(a0)
  269.         move.w    #0,aud0+ac_vol(a0)
  270.  
  271.         move.l    #ClearBuf,aud1(a0)
  272.         move.w    #40,aud1+ac_len(a0)
  273.         move.w    period,aud1+ac_per(a0)
  274.         move.w    #0,aud1+ac_vol(a0)
  275.  
  276.         move.l    #ClearBuf,aud2(a0)
  277.         move.w    #40,aud2+ac_len(a0)
  278.         move.w    period,aud2+ac_per(a0)
  279.         move.w    #0,aud2+ac_vol(a0)
  280.  
  281.         move.l    #ClearBuf,aud3(a0)
  282.         move.w    #40,aud3+ac_len(a0)
  283.         move.w    period,aud3+ac_per(a0)
  284.         move.w    #0,aud3+ac_vol(a0)
  285.  
  286.         moveq    #INTB_AUD0,d0
  287.         lea    AInt0,a1
  288.         CALLSYS    SetIntVector
  289.         move.l    d0,OldAInt0
  290.  
  291.         move.l    #QuietInst,Channel0
  292.         move.l    #QuietInst,Channel1
  293.         move.l    #QuietInst,Channel2
  294.         move.l    #QuietInst,Channel3
  295.         move.l    #QuietInst,Channel4
  296.         move.l    #QuietInst,Channel5
  297.         move.l    #QuietInst,Channel6
  298.         move.l    #QuietInst,Channel7
  299.         move.l    #QuietInst,Channel8
  300.         move.l    #QuietInst,Channel9
  301.         move.l    #QuietInst,Channel10
  302.         move.l    #QuietInst,Channel11
  303.         move.l    #QuietInst,Channel12
  304.         move.l    #QuietInst,Channel13
  305.         move.l    #QuietInst,Channel14
  306.         move.l    #QuietInst,Channel15
  307.  
  308.         clr.b    mus_playing
  309.         clr.b    mus_looping
  310.  
  311.         clr.l    MusDelay        ; MusDelay = 0
  312.         clr.l    VoiceAvail        ; all voices available
  313.  
  314.         CALLSYS    Disable
  315.         lea    _custom,a0
  316.         move.w    #$8080,intena(a0)    ; int enable
  317.         move.w    #$800F,dmacon(a0)    ; enable dma
  318.         bsr    AudioINT0        ; start audio
  319.         CALLSYS    Enable
  320.  
  321.         movem.l    (a7)+,d1-d7/a0-a6
  322.         moveq    #0,d0        ; okay
  323.         rts
  324.  
  325. .err4        movea.l    AudioIO,a1
  326.         CALLSYS    CloseDevice
  327.  
  328. .err3        movea.l    AudioIO,a0
  329.         CALLSYS    DeleteIORequest
  330.  
  331. .err2        movea.l    AudioPort,a0
  332.         CALLSYS    DeleteMsgPort
  333.  
  334. .err1        movea.l    LookupMem,a1
  335.         CALLSYS    FreeVec
  336.  
  337. .err0        movea.l    _DOSBase,a1
  338.         CALLSYS    CloseLibrary
  339.  
  340. .err        movem.l    (a7)+,d1-d7/a0-a6
  341.         moveq    #-1,d0        ; error
  342.         rts
  343.  
  344. ;--------------------------------------
  345.  
  346.         CNOP    0,16
  347.  
  348. ExitServer    movem.l    d1-d7/a0-a6,-(a7)
  349.  
  350.         lea    _custom,a0
  351.         move.w    #$0780,intena(a0)    ; kill int enable
  352.         move.w    #$0780,intreq(a0)    ; kill request
  353.         move.w    #$000F,dmacon(a0)    ; dma off
  354.  
  355.         moveq    #INTB_AUD0,d0
  356.         movea.l    OldAInt0,a1
  357.         movea.l    _ExecBase,a6
  358.         CALLSYS    SetIntVector
  359.  
  360.         movea.l    AudioIO,a1
  361.         move.w    #ADCMD_FREE,IO_COMMAND(a1)
  362.         move.b    #IOF_QUICK,IO_FLAGS(a1)
  363.         movea.l    IO_DEVICE(a1),a6
  364.         jsr    DEV_BEGINIO(a6)
  365.  
  366.         movea.l    _ExecBase,a6
  367.  
  368.         movea.l    AudioIO,a1
  369.         CALLSYS    CloseDevice
  370.  
  371.         movea.l    AudioIO,a0
  372.         CALLSYS    DeleteIORequest
  373.  
  374.         movea.l    AudioPort,a0
  375.         CALLSYS    DeleteMsgPort
  376.  
  377.         movea.l    LookupMem,a1
  378.         CALLSYS    FreeVec
  379.  
  380.         movea.l    _DOSBase,a1
  381.         CALLSYS    CloseLibrary
  382.  
  383.         movem.l    (a7)+,d1-d7/a0-a6
  384.         moveq    #0,d0
  385.         rts
  386.  
  387. ;--------------------------------------
  388.  
  389.         CNOP    0,16
  390.  
  391. Sfx_SetVol    move.w    d0,sfx_volume
  392.         rts
  393.  
  394. ;--------------------------------------
  395.  
  396.         CNOP    0,16
  397.  
  398. Sfx_Start    movem.l    d0-d4/a0-a2,-(a7)
  399.         lea    sfxVoiceTbl,a1
  400.         movea.l    (a1,d0.w*4),a1
  401.         lea    8(a0),a0
  402.         subq.l    #8,d4
  403.         move.l    a0,vc_Wave(a1)
  404.         clr.l    vc_Index(a1)
  405.         swap    d1
  406.         clr.w    d1
  407.         divu.l    #11025,d1
  408.         move.l    d1,vc_Step(a1)
  409.         clr.l    vc_Loop(a1)
  410.         lsl.l    #8,d4
  411.         move.l    d4,vc_Length(a1)
  412.  
  413.         addq.w    #1,d3        ; sep += 1
  414.         move.w    d2,d4
  415.         muls.w    d3,d4
  416.         muls.w    d3,d4
  417.         clr.w    d4
  418.         swap    d4
  419.         neg.w    d4
  420.         add.w    d2,d4        ; ltvol = vol - vol * (sep+1)^2 / 256^2
  421.         lsl.l    #8,d4
  422.         move.l    d4,vc_LtVol(a1)
  423.  
  424.         subi.l    #257,d3        ; sep -= 257
  425.         move.w    d2,d4
  426.         muls.w    d3,d4
  427.         muls.w    d3,d4
  428.         clr.w    d4
  429.         swap    d4
  430.         neg.w    d4
  431.         add.w    d2,d4        ; rtvol = vol - vol * (sep-257)^2 / 256^2
  432.         lsl.l    #8,d4
  433.         move.l    d4,vc_RtVol(a1)
  434.  
  435.         move.b    #$81,vc_Flags(a1)
  436.         movem.l    (a7)+,d0-d4/a0-a2
  437.         rts
  438.  
  439. ;--------------------------------------
  440.  
  441.         CNOP    0,16
  442.  
  443. Sfx_Update    movem.l    d0-d4/a0-a2,-(a7)
  444.         lea    sfxVoiceTbl,a1
  445.         movea.l    (a1,d0.w*4),a1
  446.         swap    d1
  447.         clr.w    d1
  448.         divu.l    #11025,d1
  449.         move.l    d1,vc_Step(a1)
  450.  
  451.         addq.w    #1,d3        ; sep += 1
  452.         move.w    d2,d4
  453.         muls.w    d3,d4
  454.         muls.w    d3,d4
  455.         clr.w    d4
  456.         swap    d4
  457.         neg.w    d4
  458.         add.w    d2,d4        ; ltvol = vol - vol * (sep+1)^2 / 256^2
  459.         lsl.l    #8,d4
  460.         move.l    d4,vc_LtVol(a1)
  461.  
  462.         subi.l    #257,d3        ; sep -= 257
  463.         move.w    d2,d4
  464.         muls.w    d3,d4
  465.         muls.w    d3,d4
  466.         clr.w    d4
  467.         swap    d4
  468.         neg.w    d4
  469.         add.w    d2,d4        ; rtvol = vol - vol * (sep-257)^2 / 256^2
  470.         lsl.l    #8,d4
  471.         move.l    d4,vc_RtVol(a1)
  472.  
  473.         movem.l    (a7)+,d0-d4/a0-a2
  474.         rts
  475.  
  476. ;--------------------------------------
  477.  
  478.         CNOP    0,16
  479.  
  480. Sfx_Stop    move.l    a0,-(a7)
  481.         lea    sfxVoiceTbl,a0
  482.         movea.l    (a0,d0.w*4),a0
  483.         bclr    #0,vc_Flags(a0)
  484.         movea.l    (a7)+,a0
  485.         rts
  486.  
  487. ;--------------------------------------
  488.  
  489.         CNOP    0,16
  490.  
  491. Sfx_Done    move.l    a0,-(a7)
  492.         lea    sfxVoiceTbl,a0
  493.         movea.l    (a0,d0.w*4),a0
  494.         moveq    #0,d0
  495.         btst    #0,vc_Flags(a0)
  496.         beq.b    .1        ; not playing
  497.         move.l    vc_Index(a0),d0
  498.         addq.l    #1,d0        ; for safety
  499. .1        movea.l    (a7)+,a0
  500.         rts
  501.  
  502. ;--------------------------------------
  503.  
  504.         CNOP    0,16
  505.  
  506. Mus_SetVol    move.w    d0,mus_volume
  507.         rts
  508.  
  509. ;--------------------------------------
  510.  
  511.         CNOP    0,16
  512.  
  513. Mus_Register    movem.l    d1-d7/a0-a6,-(sp)
  514.         bsr    Mus_Unregister
  515.  
  516.         move.l    a0,MUSMemPtr
  517.  
  518.         cmpi.l    #$4D55531A,(a0)        ; "MUS",26
  519.         bne    .err0            ; not a mus file
  520.  
  521.         move.l    MUSMemPtr,MusPtr
  522.  
  523.         bsr    TestMUSFile
  524.         beq    .err0
  525.  
  526.         move.l    InstrFile,d1
  527.         move.l    #MODE_OLDFILE,d2
  528.         CALLDOS    Open
  529.         move.l    d0,InstrHandle
  530.         beq    .err0
  531.  
  532.         move.l    #MEMF_CLEAR,d0        ; any memory
  533.         move.l    #65536,d1        ; puddle size
  534.         move.l    #32768,d2        ; threshold size
  535.         bsr    CreatePool
  536.         move.l    a0,InstrPool
  537.         beq    .err1
  538.  
  539.         movea.l    a0,a2
  540.         movea.l    MusPtr,a3
  541.  
  542.         move.w    #255,d0
  543.         lea    Instruments,a0
  544. .setinstr    move.l    #QuietInst,(a0)+
  545.         dbra    d0,.setinstr
  546.  
  547.         move.w    $C(a3),d4        ; instrCnt
  548.         ror.w    #8,d4
  549.         subq.w    #1,d4            ; for dbra
  550.  
  551.         lea    $10(a3),a3        ; instruments[]
  552.  
  553. .instrloop    moveq    #14,d0
  554.         movea.l    a2,a0
  555.         bsr    AllocPooled
  556.  
  557.         moveq    #0,d2
  558.         move.b    (a3)+,d2        ; instrument #
  559.         moveq    #0,d1
  560.         move.b    (a3)+,d1        ; offset to next instr. #
  561.         adda.l    d1,a3            ; skip it (whatever it is?)
  562.  
  563.         lea    Instruments,a0
  564.         move.l    d0,(a0,d2.w*4)
  565.         beq    .err2
  566.  
  567.         movea.l    d0,a4            ; instrument record
  568.  
  569.         bftst    (validInstr){d2:1}
  570.         beq    .next            ; no instrument
  571.  
  572.         move.l    InstrHandle,d1
  573.         lsl.l    #2,d2
  574.         moveq    #OFFSET_BEGINNING,d3
  575.         CALLDOS    Seek
  576.  
  577.         move.l    InstrHandle,d1
  578.         move.l    a4,d2
  579.         moveq    #4,d3
  580.         CALLSYS    Read            ; get instrument offset
  581.         addq.l    #1,d0
  582.         beq    .err2            ; can't read file
  583.  
  584.         move.l    InstrHandle,d1
  585.         move.l    (a4),d2
  586.         moveq    #OFFSET_BEGINNING,d3
  587.         CALLSYS    Seek
  588.  
  589.         move.l    InstrHandle,d1
  590.         move.l    a4,d2
  591.         moveq    #14,d3
  592.         CALLSYS    Read            ; get instrument header
  593.         addq.l    #1,d0
  594.         beq    .err2            ; can't read file
  595.  
  596.         move.l    in_Length(a4),d0
  597.         swap    d0
  598.         movea.l    a2,a0
  599.         bsr    AllocPooled
  600.         move.l    d0,in_Wave(a4)        ; wave data buffer
  601.         beq    .err2
  602.  
  603.         move.l    InstrHandle,d1
  604.         move.l    d0,d2
  605.         move.l    in_Length(a4),d3
  606.         swap    d3
  607.         CALLDOS    Read            ; get instrument samples
  608.         addq.l    #1,d0
  609.         beq    .err2            ; can't read file
  610.  
  611.         move.b    #1,in_Flags(a4)
  612. .next        dbra    d4,.instrloop
  613.  
  614.         move.l    InstrHandle,d1
  615.         CALLDOS    Close
  616.         clr.l    InstrHandle
  617.  
  618.         moveq    #1,d0            ; return handle=1
  619.         movem.l    (sp)+,d1-d7/a0-a6
  620.         rts
  621.  
  622. .err2        movea.l    InstrPool,a0
  623.         bsr    DeletePool
  624.         clr.l    InstrPool
  625.  
  626. .err1        move.l    InstrHandle,d1
  627.         CALLDOS    Close
  628.         clr.l    InstrHandle
  629.  
  630. .err0        moveq    #0,d0            ; return handle=0
  631.         movem.l    (sp)+,d1-d7/a0-a6
  632.         rts
  633.  
  634. ;--------------------------------------
  635.  
  636.         CNOP    0,16
  637.  
  638. Mus_Unregister    movem.l    d0-d7/a0-a6,-(a7)
  639.         bsr    Mus_Stop
  640.  
  641.         clr.l    MUSMemPtr
  642.         clr.l    MUSMemSize
  643.  
  644.         tst.l    InstrPool
  645.         beq.b    .1
  646.         movea.l    InstrPool,a0
  647.         bsr    DeletePool
  648.         clr.l    InstrPool
  649.  
  650. .1        movem.l    (a7)+,d0-d7/a0-a6
  651.         rts
  652.  
  653. ;--------------------------------------
  654.  
  655.         CNOP    0,16
  656.  
  657. Mus_Play    move.b    d1,mus_looping
  658.         move.b    #2,mus_playing        ; 2 = play from start
  659.         rts
  660.  
  661. ;--------------------------------------
  662.  
  663.         CNOP    0,16
  664.  
  665. Mus_Stop    tst.b    mus_playing
  666.         beq.b    .2
  667.         st    mus_playing        ; -1 = stop playing
  668. .1        tst.b    mus_playing
  669.         bne.b    .1
  670.  
  671. .2        move.l    #QuietInst,Channel0
  672.         move.l    #QuietInst,Channel1
  673.         move.l    #QuietInst,Channel2
  674.         move.l    #QuietInst,Channel3
  675.         move.l    #QuietInst,Channel4
  676.         move.l    #QuietInst,Channel5
  677.         move.l    #QuietInst,Channel6
  678.         move.l    #QuietInst,Channel7
  679.         move.l    #QuietInst,Channel8
  680.         move.l    #QuietInst,Channel9
  681.         move.l    #QuietInst,Channel10
  682.         move.l    #QuietInst,Channel11
  683.         move.l    #QuietInst,Channel12
  684.         move.l    #QuietInst,Channel13
  685.         move.l    #QuietInst,Channel14
  686.         move.l    #QuietInst,Channel15
  687.  
  688.         clr.b    Voice0+vc_Flags        ; disable voices
  689.         clr.b    Voice1+vc_Flags
  690.         clr.b    Voice2+vc_Flags
  691.         clr.b    Voice3+vc_Flags
  692.         clr.b    Voice4+vc_Flags
  693.         clr.b    Voice5+vc_Flags
  694.         clr.b    Voice6+vc_Flags
  695.         clr.b    Voice7+vc_Flags
  696.         clr.b    Voice8+vc_Flags
  697.         clr.b    Voice9+vc_Flags
  698.         clr.b    Voice10+vc_Flags
  699.         clr.b    Voice11+vc_Flags
  700.         clr.b    Voice12+vc_Flags
  701.         clr.b    Voice13+vc_Flags
  702.         clr.b    Voice14+vc_Flags
  703.         clr.b    Voice15+vc_Flags
  704.  
  705.         clr.b    mus_looping
  706.         clr.l    MusDelay        ; MusDelay = 0
  707.         clr.l    VoiceAvail        ; all voices available
  708.         rts
  709.  
  710. ;--------------------------------------
  711.  
  712.         CNOP    0,16
  713.  
  714. Mus_Pause    clr.b    mus_playing        ; 0 = not playing
  715.         rts
  716.  
  717. ;--------------------------------------
  718.  
  719.         CNOP    0,16
  720.  
  721. Mus_Resume    move.b    #1,mus_playing        ; 1 = play
  722.         rts
  723.  
  724. ;--------------------------------------
  725.  
  726.         CNOP    0,16
  727.  
  728. Mus_Done    moveq    #0,d0
  729.         move.b    mus_playing,d0
  730.         rts
  731.  
  732. ;------------------------------------------------------------------------
  733.  
  734.         CNOP    0,16
  735.  
  736. TestMUSFile    movea.l    MusPtr,a0
  737.         move.l    MUSMemSize,d3        ; d3 = total file size
  738.         moveq    #0,d0
  739.         move.w    4(a0),d0
  740.         beq    .fail
  741.         ror.w    #8,d0            ; score length
  742.         moveq    #0,d1
  743.         move.w    6(a0),d1
  744.         ror.w    #8,d1            ; score start
  745.         cmpi.w    #18,d1            ; start < 18? (1 instr.)
  746.         blt    .fail
  747.         add.l    d1,d0            ; d0 = total size
  748.  
  749. ;        cmp.l    d0,d3            ; = file size?
  750. ;        bne    .fail
  751.  
  752.         move.l    d0,d3
  753.         move.l    d3,MUSMemSize
  754.  
  755.         move.w    12(a0),d2
  756.         beq.b    .fail
  757.         ror.w    #8,d2            ; d2 = instr. count
  758.         subq.w    #1,d2
  759.         lea    16(a0),a1        ; a1 = * instr. list
  760. .loop        addq.l    #1,a1            ; skip instr. value
  761.         moveq    #0,d0
  762.         move.b    (a1)+,d0        ; d0 = offset to next instr.
  763.         adda.l    d0,a1            ; skip info (?)
  764.         dbra    d2,.loop        ; next
  765.         move.l    a1,d0            ; d0 = * data following list
  766.         sub.l    a0,d0            ; - file start
  767.         cmp.l    d0,d1            ; = start?
  768.         bne.b    .fail
  769.         move.b    -1(a0,d3.l),d0        ; get last byte
  770.         lsr.b    #4,d0
  771.         cmpi.b    #6,d0            ; last byte = $6x? (end)
  772.         bne.b    .fail
  773.         moveq    #1,d0            ; file okay
  774.         rts
  775.  
  776. .fail        moveq    #0,d0            ; yikes!
  777.         rts
  778.  
  779. ;------------------------------------------------------------------------
  780.  
  781.         cnop    0,16
  782.  
  783. AudioINT0    movem.l    d2-d7/a2-a6,-(a7)
  784.         move.l    chip_offset,d0
  785.         add.l    d0,chip_buffer        ; switch buffers
  786.         neg.l    d0
  787.         move.l    d0,chip_offset
  788.  
  789.         lea    _custom,a0
  790.         move.w    #$0780,intreq(a0)    ; clear int requests
  791.  
  792.         tst.b    mus_playing
  793.         bgt.b    .domus
  794.         beq.b    .musoff
  795.         addq.b    #1,mus_playing        ; now off
  796.  
  797. .musoff        move.l    #ClearBuf,aud2(a0)
  798.         move.w    #40,aud2+ac_len(a0)
  799.         move.w    period,aud2+ac_per(a0)
  800.         move.w    #0,aud2+ac_vol(a0)
  801.  
  802.         move.l    #ClearBuf,aud3(a0)
  803.         move.w    #40,aud3+ac_len(a0)
  804.         move.w    period,aud3+ac_per(a0)
  805.         move.w    #0,aud3+ac_vol(a0)
  806.  
  807.         bra    .dosfx
  808.  
  809. .domus        cmpi.b    #2,mus_playing
  810.         bne.b    .musnxt
  811.         subq.b    #1,mus_playing
  812.  
  813.         movea.l    MusPtr,a1
  814.         moveq    #0,d1
  815.         move.w    6(a1),d1        ; score start
  816.         ror.w    #8,d1
  817.         adda.l    d1,a1            ; a1 = start
  818.         move.l    a1,MusIndex        ; store index
  819.  
  820. .musnxt        subq.l    #1,MusDelay
  821.         bpl.b    .fillmus
  822.  
  823.         bsr    NextEvent
  824.  
  825. .fillmus    lea    Voice0,a0        ; music voices
  826.         movea.l    chip_buffer,a2
  827.         bsr    FillBuffer
  828.  
  829.         lea    _custom,a0
  830.  
  831.         move.l    chip_buffer,d0
  832.         move.l    d0,aud2(a0)        ; left mus
  833.         move.w    #40,aud2+ac_len(a0)    ; 80 samples
  834.         move.w    period,aud2+ac_per(a0)
  835.         move.w    mus_volume,aud2+ac_vol(a0)
  836.  
  837.         addi.l    #128,d0
  838.         move.l    d0,aud3(a0)        ; right mus
  839.         move.w    #40,aud3+ac_len(a0)    ; 80 samples
  840.         move.w    period,aud3+ac_per(a0)
  841.         move.w    mus_volume,aud3+ac_vol(a0)
  842.  
  843. .dosfx        lea    Voice16,a0        ; sound effect voices
  844.         movea.l    chip_buffer,a2
  845.         lea    256(a2),a2
  846.         bsr    FillBuffer
  847.  
  848.         lea    _custom,a0
  849.  
  850.         move.l    chip_buffer,d0
  851.         addi.l    #256,d0
  852.         move.l    d0,aud1(a0)        ; left sfx
  853.         move.w    #40,aud1+ac_len(a0)    ; 80 samples
  854.         move.w    period,aud1+ac_per(a0)
  855.         move.w    sfx_volume,aud1+ac_vol(a0)
  856.  
  857.         addi.l    #128,d0
  858.         move.l    d0,aud0(a0)        ; right sfx
  859.         move.w    #40,aud0+ac_len(a0)    ; 80 samples
  860.         move.w    period,aud0+ac_per(a0)
  861.         move.w    sfx_volume,aud0+ac_vol(a0)
  862.  
  863. .exit        movem.l    (a7)+,d2-d7/a2-a6
  864.         moveq    #0,d0
  865.         rts
  866.  
  867. ;------------------------------------------------------------------------
  868.  
  869.         CNOP    0,16
  870.  
  871. FillBuffer    movea.l    a2,a4
  872.         lea    tempAudio,a1
  873.         moveq    #4,d0
  874. .lcloop        clr.l    (a1)+
  875.         clr.l    (a1)+
  876.         clr.l    (a1)+
  877.         clr.l    (a1)+
  878.         dbra    d0,.lcloop
  879.  
  880.         lea    tempAudio+128,a1
  881.         moveq    #4,d0
  882. .rcloop        clr.l    (a1)+
  883.         clr.l    (a1)+
  884.         clr.l    (a1)+
  885.         clr.l    (a1)+
  886.         dbra    d0,.rcloop
  887.         bra.b    .1stvoice
  888.  
  889. .next        move.l    vc_Next(a0),d0        ; next voice
  890.         bne.b    .chkvoice
  891.  
  892.         lea    128(a4),a2
  893.         lea    tempAudio,a1
  894.         moveq    #4,d0
  895. .lmloop        move.l    (a1)+,(a4)+
  896.         move.l    (a1)+,(a4)+
  897.         move.l    (a1)+,(a4)+
  898.         move.l    (a1)+,(a4)+
  899.         dbra    d0,.lmloop
  900.  
  901.         lea    tempAudio+128,a1
  902.         moveq    #4,d0
  903. .rmloop        move.l    (a1)+,(a2)+
  904.         move.l    (a1)+,(a2)+
  905.         move.l    (a1)+,(a2)+
  906.         move.l    (a1)+,(a2)+
  907.         dbra    d0,.rmloop
  908.         rts
  909.  
  910. .chkvoice    movea.l    d0,a0
  911. .1stvoice    btst    #0,vc_Flags(a0)
  912.         beq.b    .next            ; not enabled
  913.  
  914. ;------------------
  915. ; do voice
  916.         btst    #7,vc_Flags(a0)
  917.         bne    .5            ; sfx
  918.  
  919.         btst    #1,vc_Flags(a0)
  920.         beq.b    .1            ; not releasing
  921.  
  922.         tst.l    vc_LtVol(a0)
  923.         beq.b    .0
  924.         subi.l    #256,vc_LtVol(a0)
  925.  
  926. .0        tst.l    vc_RtVol(a0)
  927.         beq.b    .1
  928.         subi.l    #256,vc_RtVol(a0)
  929.  
  930. .1        move.l    vc_LtVol(a0),d6
  931.         move.l    vc_RtVol(a0),d7
  932.         tst.l    d6
  933.         bne.b    .2            ; not off yet
  934.         tst.l    d7
  935.         bne.b    .2            ; not off yet
  936.  
  937.         clr.b    vc_Flags(a0)        ; voice off
  938.         bra    .next
  939.  
  940. .2        lea    tempAudio,a1        ; left buffer
  941.         movea.l    vol_lookup,a5
  942.  
  943.         movem.l    vc_Index(a0),d1-d4    ; index,step,loop,length
  944.  
  945.         movea.l    vc_Channel(a0),a3
  946.         move.l    ch_Pitch(a3),d0
  947.         muls.l    d0,d5:d2
  948.         move.w    d5,d2
  949.         swap    d2
  950.         add.l    vc_Step(a0),d2        ; final sample rate
  951.  
  952.         movea.l    vc_Wave(a0),a3        ; sample data
  953.  
  954.         moveq    #79,d5            ; 80 samples
  955. .floop        move.l    d1,d0
  956.         swap    d0
  957.         move.b    (a3,d0.w),d6        ; sample
  958.         move.b    d6,d7
  959.         move.b    (a5,d6.l),d6        ; convert
  960.         move.b    (a5,d7.l),d7        ; convert
  961.         asr.b    #2,d6
  962.         asr.b    #2,d7
  963.         add.b    d6,(a1)+        ; left sample
  964.         add.b    d7,127(a1)        ; right sample
  965.  
  966.         add.l    d2,d1
  967.         cmp.l    d4,d1
  968.         blo.b    .3
  969.         sub.l    d4,d1
  970.         add.l    d3,d1
  971.         tst.l    d3
  972.         beq.b    .4            ; no looping
  973. .3        dbra    d5,.floop
  974.         bra.b    .done            ; done with voice
  975.  
  976. ; ran out of data
  977. .4        clr.b    vc_Flags(a0)        ; voice off
  978.  
  979. .done        move.l    d1,vc_Index(a0)
  980.         bra    .next
  981.  
  982. ; do sfx voice
  983.  
  984. .5        move.l    vc_LtVol(a0),d6
  985.         move.l    vc_RtVol(a0),d7
  986.  
  987.         lea    tempAudio,a1        ; left buffer
  988.         movea.l    vol_lookup,a5
  989.  
  990.         movem.l    vc_Index(a0),d1-d4    ; index,step,loop,length
  991.  
  992.         move.l    vc_Step(a0),d2        ; sample rate
  993.         lsr.l    #8,d2
  994.  
  995.         movea.l    vc_Wave(a0),a3        ; sample data
  996.  
  997.         moveq    #79,d5            ; 80 samples
  998. .sfloop        move.l    d1,d0
  999.         lsr.l    #8,d0
  1000.         move.b    (a3,d0.l),d6        ; sample
  1001.         move.b    d6,d7
  1002.         move.b    (a5,d6.l),d6        ; convert
  1003.         move.b    (a5,d7.l),d7        ; convert
  1004.         asr.b    #1,d6
  1005.         asr.b    #1,d7
  1006.         add.b    d6,(a1)+        ; left sample
  1007.         add.b    d7,127(a1)        ; right sample
  1008.  
  1009.         add.l    d2,d1
  1010.         cmp.l    d4,d1
  1011.         bhs.b    .4            ; ran out of data
  1012.         dbra    d5,.sfloop
  1013.         bra    .done            ; done with voice
  1014.  
  1015. ;------------------------------------------------------------------------
  1016.  
  1017.         CNOP    0,16
  1018.  
  1019. NextEvent    movea.l    MusIndex,a1
  1020.  
  1021. .0        move.b    (a1)+,d0        ; get next event
  1022.         move.b    d0,d1
  1023.         lsr.b    #3,d1
  1024.         andi.w    #$E,d1            ; d1 = event type * 2
  1025.         lea    EventTable,a0
  1026.         move.w    (a0,d1.w),d1
  1027.         jsr    (a0,d1.w)        ; do event
  1028.         tst.b    d0
  1029.         bpl.b    .0            ; more events
  1030.  
  1031.         moveq    #0,d1            ; time = 0
  1032. .1        move.b    (a1)+,d0        ; get byte
  1033.         bpl.b    .2
  1034.  
  1035.         andi.w    #$7F,d0            ; kill sign bit
  1036.         or.b    d0,d1            ; time = time + 7 bits
  1037.         lsl.l    #7,d1            ; * 128
  1038.         bra.b    .1            ; get next 7 bits
  1039.  
  1040. .2        or.b    d0,d1            ; time = time + last 7 bits
  1041.         subq.l    #1,d1            ; delay = time - 1
  1042.         bmi.b    .0            ; (no delay)
  1043.  
  1044.         move.l    d1,MusDelay        ; store delay
  1045.         move.l    a1,MusIndex        ; store index
  1046.         rts
  1047.  
  1048. ;------------------------------------------------------------------------
  1049.  
  1050. Release        moveq    #15,d1
  1051.         and.b    d0,d1            ; d1 = channel
  1052.  
  1053.         lea    Channels,a0
  1054.         movea.l    (a0,d1.w*4),a0        ; channel record
  1055.         movea.l    ch_Map(a0),a0        ; channel map
  1056.  
  1057.         move.b    (a1)+,d1        ; note #
  1058.         moveq    #0,d2
  1059.         move.b    (a0,d1.w),d2        ; voice #
  1060.         beq.b    .exit            ; no mapping
  1061.  
  1062.         clr.b    (a0,d1.w)        ; clear mapping
  1063.         move.l    VoiceAvail,d3
  1064.         bclr    d2,d3            ; voice free for use
  1065.         move.l    d3,VoiceAvail
  1066.  
  1067.         lea    Voices,a0
  1068.         movea.l    (a0,d2.w*4),a0        ; voice
  1069.         bset    #1,vc_Flags(a0)        ; do release
  1070.  
  1071. .exit        rts
  1072.  
  1073. ;------------------------------------------------------------------------
  1074.  
  1075. PlayNote    moveq    #15,d1
  1076.         and.b    d0,d1            ; d1 = channel
  1077.  
  1078.         lea    Channels,a0
  1079.         movea.l    (a0,d1.w*4),a2        ; channel record
  1080.         movea.l    ch_Map(a2),a0        ; channel map
  1081.  
  1082.         moveq    #-1,d2            ; no volume change
  1083.         move.b    (a1)+,d1        ; note #
  1084.         bclr    #7,d1
  1085.         beq.b    .getvc            ; no volume
  1086.  
  1087.         moveq    #0,d2
  1088.         move.b    (a1)+,d2        ; volume
  1089.  
  1090. .getvc        moveq    #0,d3
  1091.         move.l    VoiceAvail,d4
  1092. .vloop        bset    d3,d4
  1093.         beq.b    .foundfree
  1094.         addq.b    #1,d3
  1095.         cmpi.b    #16,d3
  1096.         bne.b    .vloop
  1097. ; no free voices
  1098.         rts
  1099.  
  1100.  
  1101. .foundfree    move.b    d3,(a0,d1.w)        ; voice mapping
  1102.         move.l    d4,VoiceAvail
  1103.  
  1104.         lea    Voices,a0
  1105.         movea.l    (a0,d3.w*4),a3        ; voice
  1106.  
  1107.         tst.b    d2
  1108.         bmi.b    .skip
  1109.  
  1110. ; new channel volume
  1111.  
  1112.         move.b    d2,ch_Vol(a2)
  1113.         moveq    #0,d3
  1114.         move.b    ch_Pan(a2),d3
  1115.         addq.w    #1,d3        ; sep += 1
  1116.         move.w    d2,d4
  1117.         muls.w    d3,d4
  1118.         muls.w    d3,d4
  1119.         clr.w    d4
  1120.         swap    d4
  1121.         neg.w    d4
  1122.         add.w    d2,d4        ; ltvol = vol - vol * (sep+1)^2 / 256^2
  1123.         lsl.l    #8,d4
  1124.         move.l    d4,ch_LtVol(a2)
  1125.  
  1126.         subi.l    #257,d3        ; sep -= 257
  1127.         move.w    d2,d4
  1128.         muls.w    d3,d4
  1129.         muls.w    d3,d4
  1130.         clr.w    d4
  1131.         swap    d4
  1132.         neg.w    d4
  1133.         add.w    d2,d4        ; rtvol = vol - vol * (sep-257)^2 / 256^2
  1134.         lsl.l    #8,d4
  1135.         move.l    d4,ch_RtVol(a2)
  1136.  
  1137. .skip        move.l    ch_LtVol(a2),vc_LtVol(a3)
  1138.         move.l    ch_RtVol(a2),vc_RtVol(a3)
  1139.  
  1140.         moveq    #15,d2
  1141.         and.b    d0,d2
  1142.         cmpi.b    #15,d2
  1143.         beq.b    .percussion
  1144.  
  1145.         move.l    ch_Instr(a2),a4        ; instrument record
  1146.  
  1147.         lea    NoteTable,a0
  1148.         moveq    #72,d2            ; one octave above middle c
  1149.         sub.b    in_Base(a4),d2
  1150.         add.b    d1,d2
  1151.         move.l    (a0,d2.w*4),vc_Step(a3)    ; step value for note
  1152.  
  1153.         clr.l    vc_Index(a3)
  1154.  
  1155.         move.l    a2,vc_Channel(a3)    ; back link (for pitch wheel)
  1156.  
  1157.         move.l    in_Wave(a4),vc_Wave(a3)
  1158.         move.l    in_Loop(a4),vc_Loop(a3)
  1159.         move.l    in_Length(a4),vc_Length(a3)
  1160.         move.b    in_Flags(a4),vc_Flags(a3)
  1161. .exit        rts
  1162.  
  1163. ; for the percussion channel, the note played sets the percussion instrument
  1164.  
  1165. .percussion    move.l    #65536,vc_Step(a3)    ; sample rate always 1.0
  1166.  
  1167.         clr.l    vc_Index(a3)
  1168.  
  1169.         move.l    a2,vc_Channel(a3)    ; back link
  1170.  
  1171.         addi.b    #100,d1            ; percussion instruments
  1172.  
  1173.         lea    Instruments,a0
  1174.         move.l    (a0,d1.w*4),a0        ; instrument record
  1175.         move.l    in_Wave(a0),vc_Wave(a3)
  1176.         move.l    in_Loop(a0),vc_Loop(a3)
  1177.         move.l    in_Length(a0),vc_Length(a3)
  1178.         move.b    in_Flags(a0),vc_Flags(a3)
  1179.         rts
  1180.  
  1181. ;------------------------------------------------------------------------
  1182.  
  1183. Pitch        moveq    #15,d1
  1184.         and.b    d0,d1            ; d1 = channel
  1185.  
  1186.         lea    Channels,a0
  1187.         movea.l    (a0,d1.w*4),a2        ; channel record
  1188.  
  1189.         moveq    #0,d1
  1190.         move.b    (a1)+,d1        ; pitch wheel setting
  1191.         lea    PitchTable,a0
  1192.         move.l    (a0,d1.w*4),ch_Pitch(a2)
  1193.         rts
  1194.  
  1195. ;------------------------------------------------------------------------
  1196.  
  1197. Tempo        addq.l    #1,a1            ; skip value
  1198.         rts
  1199.  
  1200. ;------------------------------------------------------------------------
  1201.  
  1202. ChangeCtrl    moveq    #15,d1
  1203.         and.b    d0,d1            ; d1 = channel
  1204.  
  1205.         lea    Channels,a0
  1206.         movea.l    (a0,d1.w*4),a2        ; channel
  1207.  
  1208.         move.b    (a1)+,d1        ; get controller
  1209.  
  1210.         moveq    #0,d2
  1211.         move.b    (a1)+,d2        ; value
  1212.  
  1213.         tst.b    d1
  1214.         bne.b    .1
  1215.  
  1216. ; set channel instrument
  1217.  
  1218.         lea    Instruments,a0
  1219.         move.l    (a0,d2.w*4),ch_Instr(a2)
  1220.         bne.b    .0
  1221.         move.l    #QuietInst,ch_Instr(a2)
  1222. .0        rts
  1223.  
  1224. .1        cmpi.b    #3,d1            ; volume?
  1225.         bne.b    .2
  1226.  
  1227. ; set channel volume
  1228.  
  1229.         move.b    d2,ch_Vol(a2)
  1230.         moveq    #0,d3
  1231.         move.b    ch_Pan(a2),d3
  1232.         addq.w    #1,d3        ; sep += 1
  1233.         move.w    d2,d4
  1234.         muls.w    d3,d4
  1235.         muls.w    d3,d4
  1236.         clr.w    d4
  1237.         swap    d4
  1238.         neg.w    d4
  1239.         add.w    d2,d4        ; ltvol = vol - vol * (sep+1)^2 / 256^2
  1240.         lsl.l    #8,d4
  1241.         move.l    d4,ch_LtVol(a2)
  1242.  
  1243.         subi.w    #257,d3        ; sep -= 257
  1244.         move.w    d2,d4
  1245.         muls.w    d3,d4
  1246.         muls.w    d3,d4
  1247.         clr.w    d4
  1248.         swap    d4
  1249.         neg.w    d4
  1250.         add.w    d2,d4        ; rtvol = vol - vol * (sep-257)^2 / 256^2
  1251.         lsl.l    #8,d4
  1252.         move.l    d4,ch_RtVol(a2)
  1253.         rts
  1254.  
  1255. .2        cmpi.b    #4,d1            ; pan?
  1256.         bne.b    .exit
  1257.  
  1258. ; set channel pan
  1259.  
  1260.         add.b    d2,d2        ; pan -> sep
  1261.         move.b    d2,ch_Pan(a2)
  1262.         move.b    ch_Vol(a2),d2
  1263.         moveq    #0,d3
  1264.         move.b    ch_Pan(a2),d3
  1265.         addq.w    #1,d3        ; sep += 1
  1266.         move.w    d2,d4
  1267.         muls.w    d3,d4
  1268.         muls.w    d3,d4
  1269.         clr.w    d4
  1270.         swap    d4
  1271.         neg.w    d4
  1272.         add.w    d2,d4        ; ltvol = vol - vol * (sep+1)^2 / 256^2
  1273.         lsl.l    #8,d4
  1274.         move.l    d4,ch_LtVol(a2)
  1275.  
  1276.         subi.w    #257,d3        ; sep -= 257
  1277.         move.w    d2,d4
  1278.         muls.w    d3,d4
  1279.         muls.w    d3,d4
  1280.         clr.w    d4
  1281.         swap    d4
  1282.         neg.w    d4
  1283.         add.w    d2,d4        ; rtvol = vol - vol * (sep-257)^2 / 256^2
  1284.         lsl.l    #8,d4
  1285.         move.l    d4,ch_RtVol(a2)
  1286. .exit        rts
  1287.  
  1288. ;------------------------------------------------------------------------
  1289.  
  1290. NoEvent        rts
  1291.  
  1292. ;------------------------------------------------------------------------
  1293.  
  1294. EndScore    tst.b    mus_looping        ; loop?
  1295.         bne    .loop
  1296.  
  1297.         move.l    #QuietInst,Channel0
  1298.         move.l    #QuietInst,Channel1
  1299.         move.l    #QuietInst,Channel2
  1300.         move.l    #QuietInst,Channel3
  1301.         move.l    #QuietInst,Channel4
  1302.         move.l    #QuietInst,Channel5
  1303.         move.l    #QuietInst,Channel6
  1304.         move.l    #QuietInst,Channel7
  1305.         move.l    #QuietInst,Channel8
  1306.         move.l    #QuietInst,Channel9
  1307.         move.l    #QuietInst,Channel10
  1308.         move.l    #QuietInst,Channel11
  1309.         move.l    #QuietInst,Channel12
  1310.         move.l    #QuietInst,Channel13
  1311.         move.l    #QuietInst,Channel14
  1312.         move.l    #QuietInst,Channel15
  1313.  
  1314.         clr.b    Voice0+vc_Flags        ; disable voices
  1315.         clr.b    Voice1+vc_Flags
  1316.         clr.b    Voice2+vc_Flags
  1317.         clr.b    Voice3+vc_Flags
  1318.         clr.b    Voice4+vc_Flags
  1319.         clr.b    Voice5+vc_Flags
  1320.         clr.b    Voice6+vc_Flags
  1321.         clr.b    Voice7+vc_Flags
  1322.         clr.b    Voice8+vc_Flags
  1323.         clr.b    Voice9+vc_Flags
  1324.         clr.b    Voice10+vc_Flags
  1325.         clr.b    Voice11+vc_Flags
  1326.         clr.b    Voice12+vc_Flags
  1327.         clr.b    Voice13+vc_Flags
  1328.         clr.b    Voice14+vc_Flags
  1329.         clr.b    Voice15+vc_Flags
  1330.  
  1331.         clr.l    MusDelay        ; MusDelay = 0
  1332.         clr.l    VoiceAvail        ; all voices available
  1333.         clr.b    mus_playing
  1334.         addq.l    #4,a7            ; pop NextEvent
  1335.         rts
  1336.  
  1337. .loop        movea.l    MusPtr,a1
  1338.         moveq    #0,d1
  1339.         move.w    6(a1),d1        ; score start
  1340.         ror.w    #8,d1
  1341.         adda.l    d1,a1            ; a1 = start
  1342.         rts
  1343.  
  1344. ;------------------------------------------------------------------------
  1345.         cnop    0,4
  1346.  
  1347. EventTable    dc.w    Release-EventTable
  1348.         dc.w    PlayNote-EventTable
  1349.         dc.w    Pitch-EventTable
  1350.         dc.w    Tempo-EventTable
  1351.         dc.w    ChangeCtrl-EventTable
  1352.         dc.w    NoEvent-EventTable
  1353.         dc.w    EndScore-EventTable
  1354.         dc.w    NoEvent-EventTable
  1355.  
  1356. ;------------------------------------------------------------------------
  1357. ;--------------------------------------------------------------------
  1358.  
  1359.         cnop    0,4
  1360.  
  1361. CreatePool    movea.l    _ExecBase,a1
  1362.         cmpi.w    #39,LIB_VERSION(a1)
  1363.         blt.b    .nopools        ; change to bra for debugging
  1364.  
  1365.         move.l    a6,-(sp)
  1366.         movea.l    a1,a6
  1367.         CALLSYS    CreatePool
  1368.         movea.l    (sp)+,a6
  1369.         rts
  1370.  
  1371. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1372.         move.l    d0,d4            ; memory attributes
  1373.         move.l    d1,d3            ; amount to allocate when low
  1374.         move.l    d2,d5            ; size of when not to use pool
  1375.  
  1376.         exg.l    d0,d1            ; swap flags and size
  1377.         movea.l    a1,a6
  1378.         CALLSYS    AllocMem        ; get first block
  1379.         movea.l    d0,a0
  1380.         tst.l    d0
  1381.         beq.b    .exit            ; no memory!
  1382.  
  1383.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1384.         clr.l    12(a0)            ; no next block
  1385.         lea    24(a0),a1        ; first free location here
  1386.         move.l    a1,16(a0)
  1387.         subi.l    #24,d3            ; for header info
  1388.         move.l    d3,20(a0)        ; amount free in this block
  1389.  
  1390. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1391.         rts
  1392.  
  1393.         cnop    0,4
  1394.  
  1395. DeletePool    movea.l    _ExecBase,a1
  1396.         cmpi.w    #39,LIB_VERSION(a1)
  1397.         blt.b    .nopools        ; change to bra for debugging
  1398.  
  1399.         move.l    a6,-(sp)
  1400.         movea.l    a1,a6
  1401.         CALLSYS    DeletePool
  1402.         movea.l    (sp)+,a6
  1403.         rts
  1404.  
  1405. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1406.         move.l    a0,d2            ; first block
  1407.         beq.b    .exit            ; safety check
  1408.  
  1409.         movea.l    a1,a6
  1410.  
  1411. .loop        movea.l    d2,a1            ; pointer to block
  1412.         move.l    (a1),d0            ; size of block
  1413.         move.l    12(a1),d2        ; next block
  1414.         CALLSYS    FreeMem
  1415.         tst.l    d2
  1416.         bne.b    .loop
  1417.  
  1418. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1419.         rts
  1420.  
  1421.         cnop    0,4
  1422.  
  1423. AllocPooled    movea.l    _ExecBase,a1
  1424.         cmpi.w    #39,LIB_VERSION(a1)
  1425.         blt.b    .nopools        ; change to bra for debugging
  1426.  
  1427.         move.l    a6,-(sp)
  1428.         movea.l    a1,a6
  1429.         CALLSYS    AllocPooled
  1430.         movea.l    (sp)+,a6
  1431.         rts
  1432.  
  1433. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1434.         move.l    a0,d2
  1435.         beq.b    .exit            ; safety check
  1436.  
  1437.         addq.l    #3,d0
  1438.         andi.b    #$FC,d0            ; long align size
  1439.  
  1440.         movea.l    a1,a6
  1441.  
  1442.         cmp.l    8(a0),d0        ; check threshold
  1443.         blt.b    .chkpuddles        ; allocate from puddles
  1444.  
  1445.         addi.l    #24,d0            ; for header
  1446.         move.l    d0,d3            ; save size
  1447.         move.l    4(a0),d1        ; mem attrs
  1448.         CALLSYS    AllocMem
  1449.         movea.l    d0,a0
  1450.         tst.l    d0
  1451.         beq.b    .exit            ; no memory
  1452.  
  1453.         move.l    d3,(a0)            ; size of block
  1454.         clr.l    20(a0)            ; no free space in here
  1455.  
  1456.         movea.l    d2,a1            ; pool header
  1457.         move.l    12(a1),d1
  1458.         move.l    a0,12(a1)        ; splice in block
  1459.         move.l    d1,12(a0)        ; relink next block
  1460.         lea    24(a0),a0        ; skip over header
  1461.  
  1462. .exit        move.l    a0,d0
  1463.         movem.l    (sp)+,d2-d7/a2-a6
  1464.         rts
  1465.  
  1466.         cnop    0,4
  1467.  
  1468. .chkpuddles    cmp.l    20(a0),d0        ; check free space
  1469.         blt.b    .gotspace
  1470.  
  1471.         movea.l    12(a0),a0        ; next block
  1472.         move.l    a0,d1
  1473.         bne.b    .chkpuddles
  1474.  
  1475. ; not enough free space in existing puddles, create another
  1476.  
  1477.         move.l    d0,d6            ; save size
  1478.  
  1479.         movea.l    d2,a0            ; pool header
  1480.         movem.l    (a0),d3-d5
  1481.         movem.l    (a0),d0-d1
  1482.         CALLSYS    AllocMem        ; get block
  1483.         movea.l    d0,a0
  1484.         tst.l    d0
  1485.         beq.b    .out            ; no memory!
  1486.  
  1487.         movea.l    d2,a1            ; pool header
  1488.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1489.         move.l    12(a1),12(a0)        ; next block
  1490.         move.l    a0,12(a1)        ; splice in block
  1491.         lea    24(a0),a1        ; first free location here
  1492.         move.l    a1,16(a0)
  1493.         subi.l    #24,d3            ; for header info
  1494.         move.l    d3,20(a0)        ; amount free in this block
  1495.  
  1496.         move.l    d6,d0            ; restore size
  1497.  
  1498. .gotspace    sub.l    d0,20(a0)        ; sub from amount free
  1499.         bmi.b    .err            ; threshold >= puddlesize!
  1500.  
  1501.         move.l    16(a0),a1        ; free space
  1502.         add.l    d0,16(a0)        ; next free space
  1503.  
  1504.         movea.l    a1,a0
  1505.         bra.b    .out
  1506.  
  1507. .err        add.l    d0,20(a0)        ; restore free space
  1508.         moveq    #0,d0
  1509.         suba.l    a0,a0            ; no memory
  1510.  
  1511. .out        move.l    a0,d0
  1512.         movem.l    (sp)+,d2-d7/a2-a6
  1513.         rts
  1514.  
  1515. ;------------------------------------------------------------------------
  1516. ;------------------------------------------------------------------------
  1517.  
  1518.         cnop    0,4
  1519.  
  1520. MUSMemPtr    dc.l    0
  1521. MUSMemSize    dc.l    0
  1522.  
  1523. _ExecBase    dc.l    0
  1524. _DOSBase    dc.l    0
  1525. LookupMem    dc.l    0
  1526. vol_lookup    dc.l    0
  1527.  
  1528. ;------------------------------------------------------------------------
  1529.  
  1530. period        dc.w    325    ; NTSC 11025 KHz
  1531. sfx_volume    dc.w    64
  1532. mus_volume    dc.w    64
  1533. mus_playing    dc.b    0
  1534. mus_looping    dc.b    0
  1535.  
  1536. ;------------------------------------------------------------------------
  1537.  
  1538.         cnop    0,4
  1539.  
  1540. AudioPort    dc.l    0
  1541. AudioIO        dc.l    0
  1542.  
  1543. AInt0        dc.l    0,0
  1544.         dc.b    NT_INTERRUPT,0        ; LN_TYPE, LN_PRI
  1545.         dc.l    AIntName        ; LN_NAME
  1546.         dc.l    0            ; IS_DATA
  1547.         dc.l    AudioINT0        ; IS_CODE
  1548.  
  1549. MusPtr        dc.l    0
  1550. MusIndex    dc.l    0
  1551. MusDelay    dc.l    0
  1552. OldAInt0    dc.l    0
  1553.  
  1554. AudioAlloc    dc.b    $0F            ; Amiga channels to allocate
  1555.  
  1556. GfxName        dc.b    'graphics.library',0
  1557. DOSName        dc.b    'dos.library',0
  1558. AudioName    dc.b    'audio.device',0
  1559. AIntName    dc.b    'ADoom Sound Server',0
  1560.  
  1561. ;--------------------------------------
  1562.  
  1563.         CNOP    0,4
  1564.  
  1565. ; bit set if voice is in use (0-15=music voices,16-31=sfx voices)
  1566.  
  1567. VoiceAvail    dc.l    0
  1568.  
  1569. chip_buffer    dc.l    chipBuffer
  1570. chip_offset    dc.l    512
  1571.  
  1572. ;--------------------------------------------------------------------
  1573.  
  1574.         CNOP    0,4
  1575.  
  1576. NoteTable    dc.l    65536/64,69433/64,73562/64,77936/64,82570/64,87480/64,92682/64,98193/64,104032/64,110218/64,116772/64,123715/64
  1577.         dc.l    65536/32,69433/32,73562/32,77936/32,82570/32,87480/32,92682/32,98193/32,104032/32,110218/32,116772/32,123715/32
  1578.         dc.l    65536/16,69433/16,73562/16,77936/16,82570/16,87480/16,92682/16,98193/16,104032/16,110218/16,116772/16,123715/16
  1579.         dc.l    65536/8,69433/8,73562/8,77936/8,82570/8,87480/8,92682/8,98193/8,104032/8,110218/8,116772/8,123715/8
  1580.         dc.l    65536/4,69433/4,73562/4,77936/4,82570/4,87480/4,92682/4,98193/4,104032/4,110218/4,116772/4,123715/4
  1581.         dc.l    65536/2,69433/2,73562/2,77936/2,82570/2,87480/2,92682/2,98193/2,104032/2,110218/2,116772/2,123715/2
  1582.         dc.l    65536,69433,73562,77936,82570,87480,92682,98193,104032,110218,116772,123715
  1583.         dc.l    65536*2,69433*2,73562*2,77936*2,82570*2,87480*2,92682*2,98193*2,104032*2,110218*2,116772*2,123715*2
  1584.         dc.l    65536*4,69433*4,73562*4,77936*4,82570*4,87480*4,92682*4,98193*4,104032*4,110218*4,116772*4,123715*4
  1585.         dc.l    65536*8,69433*8,73562*8,77936*8,82570*8,87480*8,92682*8,98193*8,104032*8,110218*8,116772*8,123715*8
  1586.         dc.l    65536*16,69433*16,73562*16,77936*16,82570*16,87480*16,92682*16,98193*16
  1587.  
  1588. ;------------------------------------------------------------------------
  1589.  
  1590. PitchTable:
  1591.  
  1592. pitch_ix    SET    128
  1593.  
  1594.         REPT    128
  1595.         dc.l    -3678*pitch_ix/64
  1596. pitch_ix    SET    pitch_ix-1
  1597.         ENDR
  1598.  
  1599.         REPT    128
  1600.         dc.l    3897*pitch_ix/64
  1601. pitch_ix    SET    pitch_ix+1
  1602.         ENDR
  1603.  
  1604. ;------------------------------------------------------------------------
  1605.  
  1606.         STRUCTURE MusChannel,0
  1607.         APTR    ch_Instr
  1608.         APTR    ch_Map
  1609.         ULONG    ch_Pitch
  1610.         APTR    ch_LtVol
  1611.         APTR    ch_RtVol
  1612.         BYTE    ch_Vol
  1613.         BYTE    ch_Pan
  1614.  
  1615.  
  1616.         CNOP    0,4
  1617.  
  1618. Channels    dc.l    Channel0,Channel1,Channel2,Channel3
  1619.         dc.l    Channel4,Channel5,Channel6,Channel7
  1620.         dc.l    Channel8,Channel9,Channel10,Channel11
  1621.         dc.l    Channel12,Channel13,Channel14,Channel15
  1622.  
  1623.  
  1624.         CNOP    0,4
  1625.  
  1626. Channel0    dc.l    0        ; instrument
  1627.         dc.l    Channel0Map    ; note to voice map
  1628.         dc.l    0        ; pitch wheel setting
  1629.         dc.l    0        ; left volume table
  1630.         dc.l    0        ; right volume table
  1631.         dc.b    0        ; volume
  1632.         dc.b    0        ; pan setting
  1633.  
  1634.         CNOP    0,4
  1635.  
  1636. Channel1    dc.l    0        ; instrument
  1637.         dc.l    Channel1Map    ; note to voice map
  1638.         dc.l    0        ; pitch wheel setting
  1639.         dc.l    0        ; left volume table
  1640.         dc.l    0        ; right volume table
  1641.         dc.b    0        ; volume
  1642.         dc.b    0        ; pan setting
  1643.  
  1644.         CNOP    0,4
  1645.  
  1646. Channel2    dc.l    0        ; instrument
  1647.         dc.l    Channel2Map    ; note to voice map
  1648.         dc.l    0        ; pitch wheel setting
  1649.         dc.l    0        ; left volume table
  1650.         dc.l    0        ; right volume table
  1651.         dc.b    0        ; volume
  1652.         dc.b    0        ; pan setting
  1653.  
  1654.         CNOP    0,4
  1655.  
  1656. Channel3    dc.l    0        ; instrument
  1657.         dc.l    Channel3Map    ; note to voice map
  1658.         dc.l    0        ; pitch wheel setting
  1659.         dc.l    0        ; left volume table
  1660.         dc.l    0        ; right volume table
  1661.         dc.b    0        ; volume
  1662.         dc.b    0        ; pan setting
  1663.  
  1664.         CNOP    0,4
  1665.  
  1666. Channel4    dc.l    0        ; instrument
  1667.         dc.l    Channel4Map    ; note to voice map
  1668.         dc.l    0        ; pitch wheel setting
  1669.         dc.l    0        ; left volume table
  1670.         dc.l    0        ; right volume table
  1671.         dc.b    0        ; volume
  1672.         dc.b    0        ; pan setting
  1673.  
  1674.         CNOP    0,4
  1675.  
  1676. Channel5    dc.l    0        ; instrument
  1677.         dc.l    Channel5Map    ; note to voice map
  1678.         dc.l    0        ; pitch wheel setting
  1679.         dc.l    0        ; left volume table
  1680.         dc.l    0        ; right volume table
  1681.         dc.b    0        ; volume
  1682.         dc.b    0        ; pan setting
  1683.  
  1684.         CNOP    0,4
  1685.  
  1686. Channel6    dc.l    0        ; instrument
  1687.         dc.l    Channel6Map    ; note to voice map
  1688.         dc.l    0        ; pitch wheel setting
  1689.         dc.l    0        ; left volume table
  1690.         dc.l    0        ; right volume table
  1691.         dc.b    0        ; volume
  1692.         dc.b    0        ; pan setting
  1693.  
  1694.         CNOP    0,4
  1695.  
  1696. Channel7    dc.l    0        ; instrument
  1697.         dc.l    Channel7Map    ; note to voice map
  1698.         dc.l    0        ; pitch wheel setting
  1699.         dc.l    0        ; left volume table
  1700.         dc.l    0        ; right volume table
  1701.         dc.b    0        ; volume
  1702.         dc.b    0        ; pan setting
  1703.  
  1704.         CNOP    0,4
  1705.  
  1706. Channel8    dc.l    0        ; instrument
  1707.         dc.l    Channel8Map    ; note to voice map
  1708.         dc.l    0        ; pitch wheel setting
  1709.         dc.l    0        ; left volume table
  1710.         dc.l    0        ; right volume table
  1711.         dc.b    0        ; volume
  1712.         dc.b    0        ; pan setting
  1713.  
  1714.         CNOP    0,4
  1715.  
  1716. Channel9    dc.l    0        ; instrument
  1717.         dc.l    Channel9Map    ; note to voice map
  1718.         dc.l    0        ; pitch wheel setting
  1719.         dc.l    0        ; left volume table
  1720.         dc.l    0        ; right volume table
  1721.         dc.b    0        ; volume
  1722.         dc.b    0        ; pan setting
  1723.  
  1724.         CNOP    0,4
  1725.  
  1726. Channel10    dc.l    0        ; instrument
  1727.         dc.l    Channel10Map    ; note to voice map
  1728.         dc.l    0        ; pitch wheel setting
  1729.         dc.l    0        ; left volume table
  1730.         dc.l    0        ; right volume table
  1731.         dc.b    0        ; volume
  1732.         dc.b    0        ; pan setting
  1733.  
  1734.         CNOP    0,4
  1735.  
  1736. Channel11    dc.l    0        ; instrument
  1737.         dc.l    Channel11Map    ; note to voice map
  1738.         dc.l    0        ; pitch wheel setting
  1739.         dc.l    0        ; left volume table
  1740.         dc.l    0        ; right volume table
  1741.         dc.b    0        ; volume
  1742.         dc.b    0        ; pan setting
  1743.  
  1744.         CNOP    0,4
  1745.  
  1746. Channel12    dc.l    0        ; instrument
  1747.         dc.l    Channel12Map    ; note to voice map
  1748.         dc.l    0        ; pitch wheel setting
  1749.         dc.l    0        ; left volume table
  1750.         dc.l    0        ; right volume table
  1751.         dc.b    0        ; volume
  1752.         dc.b    0        ; pan setting
  1753.  
  1754.         CNOP    0,4
  1755.  
  1756. Channel13    dc.l    0        ; instrument
  1757.         dc.l    Channel13Map    ; note to voice map
  1758.         dc.l    0        ; pitch wheel setting
  1759.         dc.l    0        ; left volume table
  1760.         dc.l    0        ; right volume table
  1761.         dc.b    0        ; volume
  1762.         dc.b    0        ; pan setting
  1763.  
  1764.         CNOP    0,4
  1765.  
  1766. Channel14    dc.l    0        ; instrument
  1767.         dc.l    Channel14Map    ; note to voice map
  1768.         dc.l    0        ; pitch wheel setting
  1769.         dc.l    0        ; left volume table
  1770.         dc.l    0        ; right volume table
  1771.         dc.b    0        ; volume
  1772.         dc.b    0        ; pan setting
  1773.  
  1774.         CNOP    0,4
  1775.  
  1776. Channel15    dc.l    0        ; instrument
  1777.         dc.l    Channel15Map    ; note to voice map
  1778.         dc.l    0        ; pitch wheel setting
  1779.         dc.l    0        ; left volume table
  1780.         dc.l    0        ; right volume table
  1781.         dc.b    0        ; volume
  1782.         dc.b    0        ; pan setting
  1783.  
  1784.  
  1785.         CNOP    0,4
  1786.  
  1787. Channel0Map    dcb.b    128,0
  1788. Channel1Map    dcb.b    128,0
  1789. Channel2Map    dcb.b    128,0
  1790. Channel3Map    dcb.b    128,0
  1791. Channel4Map    dcb.b    128,0
  1792. Channel5Map    dcb.b    128,0
  1793. Channel6Map    dcb.b    128,0
  1794. Channel7Map    dcb.b    128,0
  1795. Channel8Map    dcb.b    128,0
  1796. Channel9Map    dcb.b    128,0
  1797. Channel10Map    dcb.b    128,0
  1798. Channel11Map    dcb.b    128,0
  1799. Channel12Map    dcb.b    128,0
  1800. Channel13Map    dcb.b    128,0
  1801. Channel14Map    dcb.b    128,0
  1802. Channel15Map    dcb.b    128,0
  1803.  
  1804. ;--------------------------------------
  1805.  
  1806.         STRUCTURE AudioVoice,0
  1807.         APTR    vc_Next
  1808.         APTR    vc_Channel
  1809.         APTR    vc_Wave
  1810.         ULONG    vc_Index
  1811.         ULONG    vc_Step
  1812.         ULONG    vc_Loop
  1813.         ULONG    vc_Length
  1814.         APTR    vc_LtVol
  1815.         APTR    vc_RtVol
  1816.         BYTE    vc_Flags    ; b7 = SFX, b1 = RLS, b0 = EN
  1817.  
  1818.         CNOP    0,4
  1819.  
  1820. Voices        dc.l    Voice0,Voice1,Voice2,Voice3
  1821.         dc.l    Voice4,Voice5,Voice6,Voice7
  1822.         dc.l    Voice8,Voice9,Voice10,Voice11
  1823.         dc.l    Voice12,Voice13,Voice14,Voice15
  1824.  
  1825. sfxVoiceTbl    dc.l    Voice16,Voice17,Voice18,Voice19
  1826.         dc.l    Voice20,Voice21,Voice22,Voice23
  1827.         dc.l    Voice24,Voice25,Voice26,Voice27
  1828.         dc.l    Voice28,Voice29,Voice30,Voice31
  1829.  
  1830. ; Music Voices
  1831.  
  1832.         CNOP    0,4
  1833.  
  1834. Voice0        dc.l    Voice1
  1835.         dc.l    0        ; channel back-link
  1836.         dc.l    0        ; instrument wave data
  1837.         dc.l    0        ; sample index
  1838.         dc.l    0        ; sample rate
  1839.         dc.l    0        ; instrument loop point
  1840.         dc.l    0        ; instrument data length
  1841.         dc.l    0        ; left volume table
  1842.         dc.l    0        ; right volume table
  1843.         dc.b    0        ; voice flags
  1844.  
  1845.         CNOP    0,4
  1846.  
  1847. Voice1        dc.l    Voice2
  1848.         dc.l    0        ; channel back-link
  1849.         dc.l    0        ; instrument wave data
  1850.         dc.l    0        ; sample index
  1851.         dc.l    0        ; sample rate
  1852.         dc.l    0        ; instrument loop point
  1853.         dc.l    0        ; instrument data length
  1854.         dc.l    0        ; left volume table
  1855.         dc.l    0        ; right volume table
  1856.         dc.b    0        ; voice flags
  1857.  
  1858.         CNOP    0,4
  1859.  
  1860. Voice2        dc.l    Voice3
  1861.         dc.l    0        ; channel back-link
  1862.         dc.l    0        ; instrument wave data
  1863.         dc.l    0        ; sample index
  1864.         dc.l    0        ; sample rate
  1865.         dc.l    0        ; instrument loop point
  1866.         dc.l    0        ; instrument data length
  1867.         dc.l    0        ; left volume table
  1868.         dc.l    0        ; right volume table
  1869.         dc.b    0        ; voice flags
  1870.  
  1871.         CNOP    0,4
  1872.  
  1873. Voice3        dc.l    Voice4
  1874.         dc.l    0        ; channel back-link
  1875.         dc.l    0        ; instrument wave data
  1876.         dc.l    0        ; sample index
  1877.         dc.l    0        ; sample rate
  1878.         dc.l    0        ; instrument loop point
  1879.         dc.l    0        ; instrument data length
  1880.         dc.l    0        ; left volume table
  1881.         dc.l    0        ; right volume table
  1882.         dc.b    0        ; voice flags
  1883.  
  1884.         CNOP    0,4
  1885.  
  1886. Voice4        dc.l    Voice5
  1887.         dc.l    0        ; channel back-link
  1888.         dc.l    0        ; instrument wave data
  1889.         dc.l    0        ; sample index
  1890.         dc.l    0        ; sample rate
  1891.         dc.l    0        ; instrument loop point
  1892.         dc.l    0        ; instrument data length
  1893.         dc.l    0        ; left volume table
  1894.         dc.l    0        ; right volume table
  1895.         dc.b    0        ; voice flags
  1896.  
  1897.         CNOP    0,4
  1898.  
  1899. Voice5        dc.l    Voice6
  1900.         dc.l    0        ; channel back-link
  1901.         dc.l    0        ; instrument wave data
  1902.         dc.l    0        ; sample index
  1903.         dc.l    0        ; sample rate
  1904.         dc.l    0        ; instrument loop point
  1905.         dc.l    0        ; instrument data length
  1906.         dc.l    0        ; left volume table
  1907.         dc.l    0        ; right volume table
  1908.         dc.b    0        ; voice flags
  1909.  
  1910.         CNOP    0,4
  1911.  
  1912. Voice6        dc.l    Voice7
  1913.         dc.l    0        ; channel back-link
  1914.         dc.l    0        ; instrument wave data
  1915.         dc.l    0        ; sample index
  1916.         dc.l    0        ; sample rate
  1917.         dc.l    0        ; instrument loop point
  1918.         dc.l    0        ; instrument data length
  1919.         dc.l    0        ; left volume table
  1920.         dc.l    0        ; right volume table
  1921.         dc.b    0        ; voice flags
  1922.  
  1923.         CNOP    0,4
  1924.  
  1925. Voice7        dc.l    Voice8
  1926.         dc.l    0        ; channel back-link
  1927.         dc.l    0        ; instrument wave data
  1928.         dc.l    0        ; sample index
  1929.         dc.l    0        ; sample rate
  1930.         dc.l    0        ; instrument loop point
  1931.         dc.l    0        ; instrument data length
  1932.         dc.l    0        ; left volume table
  1933.         dc.l    0        ; right volume table
  1934.         dc.b    0        ; voice flags
  1935.  
  1936.         CNOP    0,4
  1937.  
  1938. Voice8        dc.l    Voice9
  1939.         dc.l    0        ; channel back-link
  1940.         dc.l    0        ; instrument wave data
  1941.         dc.l    0        ; sample index
  1942.         dc.l    0        ; sample rate
  1943.         dc.l    0        ; instrument loop point
  1944.         dc.l    0        ; instrument data length
  1945.         dc.l    0        ; left volume table
  1946.         dc.l    0        ; right volume table
  1947.         dc.b    0        ; voice flags
  1948.  
  1949.         CNOP    0,4
  1950.  
  1951. Voice9        dc.l    Voice10
  1952.         dc.l    0        ; channel back-link
  1953.         dc.l    0        ; instrument wave data
  1954.         dc.l    0        ; sample index
  1955.         dc.l    0        ; sample rate
  1956.         dc.l    0        ; instrument loop point
  1957.         dc.l    0        ; instrument data length
  1958.         dc.l    0        ; left volume table
  1959.         dc.l    0        ; right volume table
  1960.         dc.b    0        ; voice flags
  1961.  
  1962.         CNOP    0,4
  1963.  
  1964. Voice10        dc.l    Voice11
  1965.         dc.l    0        ; channel back-link
  1966.         dc.l    0        ; instrument wave data
  1967.         dc.l    0        ; sample index
  1968.         dc.l    0        ; sample rate
  1969.         dc.l    0        ; instrument loop point
  1970.         dc.l    0        ; instrument data length
  1971.         dc.l    0        ; left volume table
  1972.         dc.l    0        ; right volume table
  1973.         dc.b    0        ; voice flags
  1974.  
  1975.         CNOP    0,4
  1976.  
  1977. Voice11        dc.l    Voice12
  1978.         dc.l    0        ; channel back-link
  1979.         dc.l    0        ; instrument wave data
  1980.         dc.l    0        ; sample index
  1981.         dc.l    0        ; sample rate
  1982.         dc.l    0        ; instrument loop point
  1983.         dc.l    0        ; instrument data length
  1984.         dc.l    0        ; left volume table
  1985.         dc.l    0        ; right volume table
  1986.         dc.b    0        ; voice flags
  1987.  
  1988.         CNOP    0,4
  1989.  
  1990. Voice12        dc.l    Voice13
  1991.         dc.l    0        ; channel back-link
  1992.         dc.l    0        ; instrument wave data
  1993.         dc.l    0        ; sample index
  1994.         dc.l    0        ; sample rate
  1995.         dc.l    0        ; instrument loop point
  1996.         dc.l    0        ; instrument data length
  1997.         dc.l    0        ; left volume table
  1998.         dc.l    0        ; right volume table
  1999.         dc.b    0        ; voice flags
  2000.  
  2001.         CNOP    0,4
  2002.  
  2003. Voice13        dc.l    Voice14
  2004.         dc.l    0        ; channel back-link
  2005.         dc.l    0        ; instrument wave data
  2006.         dc.l    0        ; sample index
  2007.         dc.l    0        ; sample rate
  2008.         dc.l    0        ; instrument loop point
  2009.         dc.l    0        ; instrument data length
  2010.         dc.l    0        ; left volume table
  2011.         dc.l    0        ; right volume table
  2012.         dc.b    0        ; voice flags
  2013.  
  2014.         CNOP    0,4
  2015.  
  2016. Voice14        dc.l    Voice15
  2017.         dc.l    0        ; channel back-link
  2018.         dc.l    0        ; instrument wave data
  2019.         dc.l    0        ; sample index
  2020.         dc.l    0        ; sample rate
  2021.         dc.l    0        ; instrument loop point
  2022.         dc.l    0        ; instrument data length
  2023.         dc.l    0        ; left volume table
  2024.         dc.l    0        ; right volume table
  2025.         dc.b    0        ; voice flags
  2026.  
  2027.         CNOP    0,4
  2028.  
  2029. Voice15        dc.l    0
  2030.         dc.l    0        ; channel back-link
  2031.         dc.l    0        ; instrument wave data
  2032.         dc.l    0        ; sample index
  2033.         dc.l    0        ; sample rate
  2034.         dc.l    0        ; instrument loop point
  2035.         dc.l    0        ; instrument data length
  2036.         dc.l    0        ; left volume table
  2037.         dc.l    0        ; right volume table
  2038.         dc.b    0        ; voice flags
  2039.  
  2040. ; Sound Effect Voices
  2041.  
  2042.         CNOP    0,4
  2043.  
  2044. Voice16        dc.l    Voice17
  2045.         dc.l    0        ; channel back-link
  2046.         dc.l    0        ; instrument wave data
  2047.         dc.l    0        ; sample index
  2048.         dc.l    0        ; sample rate
  2049.         dc.l    0        ; instrument loop point
  2050.         dc.l    0        ; instrument data length
  2051.         dc.l    0        ; left volume table
  2052.         dc.l    0        ; right volume table
  2053.         dc.b    0        ; voice flags
  2054.  
  2055.         CNOP    0,4
  2056.  
  2057. Voice17        dc.l    Voice18
  2058.         dc.l    0        ; channel back-link
  2059.         dc.l    0        ; instrument wave data
  2060.         dc.l    0        ; sample index
  2061.         dc.l    0        ; sample rate
  2062.         dc.l    0        ; instrument loop point
  2063.         dc.l    0        ; instrument data length
  2064.         dc.l    0        ; left volume table
  2065.         dc.l    0        ; right volume table
  2066.         dc.b    0        ; voice flags
  2067.  
  2068.         CNOP    0,4
  2069.  
  2070. Voice18        dc.l    Voice19
  2071.         dc.l    0        ; channel back-link
  2072.         dc.l    0        ; instrument wave data
  2073.         dc.l    0        ; sample index
  2074.         dc.l    0        ; sample rate
  2075.         dc.l    0        ; instrument loop point
  2076.         dc.l    0        ; instrument data length
  2077.         dc.l    0        ; left volume table
  2078.         dc.l    0        ; right volume table
  2079.         dc.b    0        ; voice flags
  2080.  
  2081.         CNOP    0,4
  2082.  
  2083. Voice19        dc.l    Voice20
  2084.         dc.l    0        ; channel back-link
  2085.         dc.l    0        ; instrument wave data
  2086.         dc.l    0        ; sample index
  2087.         dc.l    0        ; sample rate
  2088.         dc.l    0        ; instrument loop point
  2089.         dc.l    0        ; instrument data length
  2090.         dc.l    0        ; left volume table
  2091.         dc.l    0        ; right volume table
  2092.         dc.b    0        ; voice flags
  2093.  
  2094.         CNOP    0,4
  2095.  
  2096. Voice20        dc.l    Voice21
  2097.         dc.l    0        ; channel back-link
  2098.         dc.l    0        ; instrument wave data
  2099.         dc.l    0        ; sample index
  2100.         dc.l    0        ; sample rate
  2101.         dc.l    0        ; instrument loop point
  2102.         dc.l    0        ; instrument data length
  2103.         dc.l    0        ; left volume table
  2104.         dc.l    0        ; right volume table
  2105.         dc.b    0        ; voice flags
  2106.  
  2107.         CNOP    0,4
  2108.  
  2109. Voice21        dc.l    Voice22
  2110.         dc.l    0        ; channel back-link
  2111.         dc.l    0        ; instrument wave data
  2112.         dc.l    0        ; sample index
  2113.         dc.l    0        ; sample rate
  2114.         dc.l    0        ; instrument loop point
  2115.         dc.l    0        ; instrument data length
  2116.         dc.l    0        ; left volume table
  2117.         dc.l    0        ; right volume table
  2118.         dc.b    0        ; voice flags
  2119.  
  2120.         CNOP    0,4
  2121.  
  2122. Voice22        dc.l    Voice23
  2123.         dc.l    0        ; channel back-link
  2124.         dc.l    0        ; instrument wave data
  2125.         dc.l    0        ; sample index
  2126.         dc.l    0        ; sample rate
  2127.         dc.l    0        ; instrument loop point
  2128.         dc.l    0        ; instrument data length
  2129.         dc.l    0        ; left volume table
  2130.         dc.l    0        ; right volume table
  2131.         dc.b    0        ; voice flags
  2132.  
  2133.         CNOP    0,4
  2134.  
  2135. Voice23        dc.l    Voice24
  2136.         dc.l    0        ; channel back-link
  2137.         dc.l    0        ; instrument wave data
  2138.         dc.l    0        ; sample index
  2139.         dc.l    0        ; sample rate
  2140.         dc.l    0        ; instrument loop point
  2141.         dc.l    0        ; instrument data length
  2142.         dc.l    0        ; left volume table
  2143.         dc.l    0        ; right volume table
  2144.         dc.b    0        ; voice flags
  2145.  
  2146.         CNOP    0,4
  2147.  
  2148. Voice24        dc.l    Voice25
  2149.         dc.l    0        ; channel back-link
  2150.         dc.l    0        ; instrument wave data
  2151.         dc.l    0        ; sample index
  2152.         dc.l    0        ; sample rate
  2153.         dc.l    0        ; instrument loop point
  2154.         dc.l    0        ; instrument data length
  2155.         dc.l    0        ; left volume table
  2156.         dc.l    0        ; right volume table
  2157.         dc.b    0        ; voice flags
  2158.  
  2159.         CNOP    0,4
  2160.  
  2161. Voice25        dc.l    Voice26
  2162.         dc.l    0        ; channel back-link
  2163.         dc.l    0        ; instrument wave data
  2164.         dc.l    0        ; sample index
  2165.         dc.l    0        ; sample rate
  2166.         dc.l    0        ; instrument loop point
  2167.         dc.l    0        ; instrument data length
  2168.         dc.l    0        ; left volume table
  2169.         dc.l    0        ; right volume table
  2170.         dc.b    0        ; voice flags
  2171.  
  2172.         CNOP    0,4
  2173.  
  2174. Voice26        dc.l    Voice27
  2175.         dc.l    0        ; channel back-link
  2176.         dc.l    0        ; instrument wave data
  2177.         dc.l    0        ; sample index
  2178.         dc.l    0        ; sample rate
  2179.         dc.l    0        ; instrument loop point
  2180.         dc.l    0        ; instrument data length
  2181.         dc.l    0        ; left volume table
  2182.         dc.l    0        ; right volume table
  2183.         dc.b    0        ; voice flags
  2184.  
  2185.         CNOP    0,4
  2186.  
  2187. Voice27        dc.l    Voice28
  2188.         dc.l    0        ; channel back-link
  2189.         dc.l    0        ; instrument wave data
  2190.         dc.l    0        ; sample index
  2191.         dc.l    0        ; sample rate
  2192.         dc.l    0        ; instrument loop point
  2193.         dc.l    0        ; instrument data length
  2194.         dc.l    0        ; left volume table
  2195.         dc.l    0        ; right volume table
  2196.         dc.b    0        ; voice flags
  2197.  
  2198.         CNOP    0,4
  2199.  
  2200. Voice28        dc.l    Voice29
  2201.         dc.l    0        ; channel back-link
  2202.         dc.l    0        ; instrument wave data
  2203.         dc.l    0        ; sample index
  2204.         dc.l    0        ; sample rate
  2205.         dc.l    0        ; instrument loop point
  2206.         dc.l    0        ; instrument data length
  2207.         dc.l    0        ; left volume table
  2208.         dc.l    0        ; right volume table
  2209.         dc.b    0        ; voice flags
  2210.  
  2211.         CNOP    0,4
  2212.  
  2213. Voice29        dc.l    Voice30
  2214.         dc.l    0        ; channel back-link
  2215.         dc.l    0        ; instrument wave data
  2216.         dc.l    0        ; sample index
  2217.         dc.l    0        ; sample rate
  2218.         dc.l    0        ; instrument loop point
  2219.         dc.l    0        ; instrument data length
  2220.         dc.l    0        ; left volume table
  2221.         dc.l    0        ; right volume table
  2222.         dc.b    0        ; voice flags
  2223.  
  2224.         CNOP    0,4
  2225.  
  2226. Voice30        dc.l    Voice31
  2227.         dc.l    0        ; channel back-link
  2228.         dc.l    0        ; instrument wave data
  2229.         dc.l    0        ; sample index
  2230.         dc.l    0        ; sample rate
  2231.         dc.l    0        ; instrument loop point
  2232.         dc.l    0        ; instrument data length
  2233.         dc.l    0        ; left volume table
  2234.         dc.l    0        ; right volume table
  2235.         dc.b    0        ; voice flags
  2236.  
  2237.         CNOP    0,4
  2238.  
  2239. Voice31        dc.l    0
  2240.         dc.l    0        ; channel back-link
  2241.         dc.l    0        ; instrument wave data
  2242.         dc.l    0        ; sample index
  2243.         dc.l    0        ; sample rate
  2244.         dc.l    0        ; instrument loop point
  2245.         dc.l    0        ; instrument data length
  2246.         dc.l    0        ; left volume table
  2247.         dc.l    0        ; right volume table
  2248.         dc.b    0        ; voice flags
  2249.  
  2250. ;--------------------------------------
  2251.  
  2252.         STRUCTURE InstrumentRec,0
  2253.         APTR    in_Wave
  2254.         ULONG    in_Loop
  2255.         ULONG    in_Length
  2256.         BYTE    in_Flags
  2257.         BYTE    in_Base
  2258.  
  2259.  
  2260.         CNOP    0,4
  2261.  
  2262. Instruments    dcb.l    256,0
  2263.  
  2264.         CNOP    0,4
  2265.  
  2266. QuietInst    dc.l    0
  2267.         dc.l    0
  2268.         dc.l    0
  2269.         dc.b    0
  2270.         dc.b    0
  2271.  
  2272.  
  2273.         CNOP    0,4
  2274.  
  2275. InstrHandle    dc.l    0
  2276. InstrFile    dc.l    InstrName
  2277. InstrPool    dc.l    0
  2278.  
  2279. InstrName    dc.b    'MIDI_Instruments',0
  2280.  
  2281.         CNOP    0,4
  2282.  
  2283. validInstr    dc.b    %11111111    ; (00-07) Piano
  2284.         dc.b    %11111111    ; (08-0F) Chrom Perc
  2285.         dc.b    %11111111    ; (10-17) Organ
  2286.         dc.b    %11111111    ; (18-1F) Guitar
  2287.         dc.b    %11111111    ; (20-27) Bass
  2288.         dc.b    %11111111    ; (28-2F) Strings
  2289.         dc.b    %11111111    ; (30-37) Ensemble
  2290.         dc.b    %11111111    ; (38-3F) Brass
  2291.         dc.b    %11111111    ; (40-47) Reed
  2292.         dc.b    %11111111    ; (48-4F) Pipe
  2293.         dc.b    %11111111    ; (50-57) Synth Lead
  2294.         dc.b    %11111111    ; (58-5F) Synth Pad
  2295.         dc.b    %11111111    ; (60-67) Synth Effects
  2296.         dc.b    %11111111    ; (68-6F) Ethnic
  2297.         dc.b    %11111111    ; (70-77) Percussive
  2298.         dc.b    %11111111    ; (78-7F) SFX
  2299.         dc.b    %00000001    ; (80-87) invalid,Drum
  2300.         dc.b    %11111111    ; (88-8F) Drums/Clap/Hi-Hat
  2301.         dc.b    %11111111    ; (90-97) Hi-Hats/Toms/Cymb1
  2302.         dc.b    %11111111    ; (98-9F) Cymbals/Bells/Slap
  2303.         dc.b    %11111111    ; (A0-A7) Bongos/Congas/Timb
  2304.         dc.b    %11111111    ; (A8-AF) Agogo/Whistles/Gui
  2305.         dc.b    %11111100    ; (B0-B7) Claves/Block/Trian
  2306.         dc.b    %00000000    ; (B8-BF) invalid
  2307.         dc.b    %00000000    ; (C0-C7)
  2308.         dc.b    %00000000    ; (C8-CF)
  2309.         dc.b    %00000000    ; (D0-D7)
  2310.         dc.b    %00000000    ; (D8-DF)
  2311.         dc.b    %00000000    ; (E0-E7)
  2312.         dc.b    %00000000    ; (E8-EF)
  2313.         dc.b    %00000000    ; (F0-F7)
  2314.         dc.b    %00000000    ; (F8-FF)
  2315.  
  2316. ;--------------------------------------------------------------------
  2317.         section    PlayMusChip,data_c
  2318.  
  2319. chipBuffer    dcb.b    1024,0
  2320.  
  2321. ClearBuf    dcb.b    160,0
  2322.  
  2323. ;------------------------------------------------------------------------
  2324.         section    PlayMusBSS,bss
  2325.  
  2326. tempAudio    ds.b    256
  2327.  
  2328. ;------------------------------------------------------------------------
  2329.  
  2330.         end
  2331.